//
//  AmountCell.m
//  DebugDemo
//
//  Created by XFB on 2018/11/28.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "AmountCell.h"
#import "AmountModel.h"
#import "SecondAmoutCell.h"
#import "SecondAmountHeaderView.h"
#import "SecondAmountFooterView.h"

@interface AmountCell () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *secondTableView;
@property (nonatomic, strong) NSMutableArray *secondDataSource;

@end

@implementation AmountCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.secondDataSource = @[].mutableCopy;
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.secondTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.secondTableView.delegate = self;
    self.secondTableView.dataSource = self;
    self.secondTableView.scrollEnabled = NO;
    self.secondTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.secondTableView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.secondTableView];

    [self.secondTableView registerNib:[UINib nibWithNibName:@"SecondAmoutCell" bundle:nil] forCellReuseIdentifier:@"secondAmoutCell"];
}

- (void)setAmountModel:(AmountModel *)amountModel
{
    _amountModel = amountModel;
    self.secondTableView.frame = amountModel.secondTableViewF;
    [self.secondTableView reloadData];
}

#pragma mark --- <UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.amountModel.objList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    AmountModel_ObjList *objcListM = self.amountModel.objList[section];
    return objcListM.terminalList.count;
}

#pragma mark --- <UITableViewDelegate>

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SecondAmoutCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondAmoutCell"];
    AmountModel_ObjList *objcListM = self.amountModel.objList[indexPath.section];
    cell.terminalList = objcListM.terminalList[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    SecondAmountHeaderView *headerView = [SecondAmountHeaderView secondAmountHeaderViewWithTableView:tableView];
    AmountModel_ObjList *objcListM = self.amountModel.objList[section];
    headerView.objcListModel = objcListM;
    return headerView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    SecondAmountFooterView *footerView = [SecondAmountFooterView secondAmountFooterViewWithTableView:tableView];
    return footerView;
}

@end
